﻿using System;
using System.Text;

namespace TemplateMethod
{
    public class StringDisplay : AbstractDisplay
    {
        private string str;
        private int width;

        public StringDisplay(string str)
        {
            Encoding enc = Encoding.GetEncoding("shift_jis");

            this.str = str;
            this.width = enc.GetByteCount(str);
        }

        public override void Open()
        {
            PrintLine();
        }

        public override void Print()
        {
            Console.WriteLine("|" + str + "|");
        }

        public override void Close()
        {
            PrintLine();
        }


        private void PrintLine()
        {
            Console.Write("+");

            for (int i = 0; i < width; i++)
            {
                Console.Write("-");
            }

            Console.WriteLine("+");
        }
    }
}
